<?php
/*
Aurus CMS - free OOP CMS
Copyright (C) 2010  Nestor Yanchuk

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('ROOT')) die();

if (!isset($_SERVER['REQUEST_URI']) && isset($_SERVER['QUERY_STRING'])) {
	$_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
}

date_default_timezone_set('Europe/Dublin');

/**
 * Current version
 *
 * @var string
 */
define('VERSION', '1.5-dev');

/**
 * Developer mode
 *
 * @var bool
 */
define('DEV_MODE', true);

/**
 * Error reporting level 
 * @var int 0 in releases
 */
error_reporting(DEV_MODE ? E_ALL : 0);

function __autoload($class) {
	$classType = explode('_', $class, 2);
	switch ($classType[0]) {
		case 'Module':
			if(is_file(MAINDIR . '/modules/' . $classType[1] . '/main.php')){
				include MAINDIR . '/modules/' . $classType[1] . '/main.php';
			}
			break;
		case 'Plugin':
			if(is_file(MAINDIR . '/plugins/' . $classType[1] . '.php')) {
			include MAINDIR . '/plugins/' . $classType[1] . '.php';
			}
			break;
		default:
			if (is_file(MAINDIR . '/classes/' . strtolower($class) . '/class.php')) {
				include MAINDIR . '/classes/' . strtolower($class) . '/class.php';
			} else {
				error('Class "'.$class.'" was not found');
			}
			break;
	}
}

/**
 * Site address
 * http://example.com/
 *
 * Don`t forget "/" in the end
 *
 * @var string
 */
define('LINK_ROOT', Config::get('site_address'));

/**
 * The time in Unix timestamp format of the Prime Meridian
 *
 * @var int
 */
define('TIME', time() - (date('Z')));

/**
 * New line symvol in MAC format
 *
 * @var string
 */
define('R', chr(13));

/**
 * New line symvol in *nix format
 *
 * @var string
 */
define('N', chr(10));

/**
 * New line symvol in Windows format 
 *
 * @var string
 */
define('RN', R . N);

include (MAINDIR . '/functions.php');
include (MAINDIR . '/interfaces/core.php');

mb_internal_encoding('UTF-8');

Security::cleanInData();
Url::parseGet();
Lang::init();